// var db = require("../config/db");
var fs = require('fs');
var mod = {
    // 获取部门列表
   uploadImg(req, res) {
    console.log('req.files:::', req.files);
    const file = req.files[0];
    // const des_file = '../public/upload/' + file.originalname;
    const des_file = './public/upload/' + file.originalname;
    console.log('des_file:::', des_file);
    console.log('req.socket.remotePort::', req.socket.remotePort);
    fs.readFile(file.path, function(err, data) {
        if(err) {
            console.error('upload::err:::', err);
        } else {
            console.log('readfile::data:::', data);
            fs.writeFile(des_file, data, function(werr) {
                if(werr) {
                    console.log('write:;err:::', werr);
                } else {
                    res.json({
                        returnCode: 200,
                        url: des_file,
                        message: 'upload成功！'
                    });
                }
            });
        }
    })
    
   }
}

module.exports = mod;